#include <iostream>
#include <cstring>

using namespace std;

void deletelstr(char *str, const char *substr)
{
    if(str == nullptr || substr == nullptr) return;

    size_t slen = strlen(substr);
    if(slen == 0) return;                       // 如果子串的长度为空，直接返回，否则会死循环
    
    while(true)
    {
        char *p = strstr(str, substr);
        if(p == nullptr) return;

        size_t len = strlen(str);

        memmove(p, p+slen, len-(p-str)-slen+1);
    }
}

int main(void)
{
    char str[31] = "aaaxyxyzzaa";
    char substr[31] = "xyz";
    deletelstr(str, substr);
    cout << '=' << str << '=' << endl;
    return 0;
}
